package com.vecspace.dayu.code.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.vecspace.database.dao.BaseDao;
import com.vecspace.dayu.code.pojo.ProjectCatalog;

/** DAYU_CODE_PROJECT_CATALOG,操作数据库的dao类
 * @author: wanghua
 * @reviewer:
 */
@Repository("dayu_projectCatalogDao")
public class ProjectCatalogDao extends BaseDao {
	/** 根据ID查询 DAYU_CODE_PROJECT_CATALOG
	 * @param id   主键值
	 * @return ProjectCatalog
	 * @throws Exception
	 * @author wanghua
	 */
	public ProjectCatalog getProjectCatalog(Long id) throws Exception {
		ProjectCatalog projectCatalog = null;
		if (id != null && id != 0) {

			projectCatalog = this.queryObject(ProjectCatalog.class, id);
			this.evict(projectCatalog);
		}
		return projectCatalog;
	}

//	public List<ProjectCatalog> getProjectCatalogs() throws Exception{
//		List<ProjectCatalog> catalogs = this.queryObjectList("from ProjectCatalog order by ordnum");
//		return catalogs;
//	}
	
	public List<ProjectCatalog> getChildProjectCatalogs(Long pId) throws Exception{
		if(pId == null || pId.longValue() == 0) {
			pId = -1L;
		}
		List<ProjectCatalog> catalogs = this.queryObjectList("from ProjectCatalog where parentId=?0 order by ordnum", new Object[] {pId});
		return catalogs;
	}
	
	/** 插入或修改 DAYU_CODE_PROJECT_CATALOG 
	 * @param item	要保存的对象
	 * @return void
	 * @throws Exception
	 * @author wanghua
	 */
	public void saveProjectCatalog(ProjectCatalog item) throws Exception {
		this.saveOrUpdateObject(item);
		this.evict(item);
	}

	/** 根据ID删除 DAYU_CODE_PROJECT_CATALOG 
	 * @param id	主键值
	 * @return void
	 * @throws Exception
	 * @author wanghua
	 */
	public void deleteProjectCatalog(Long id) throws Exception {
		if (id != null && id != 0) {
			this.deleteObject(ProjectCatalog.class, id);
		}
	}
}
